#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;

class Solution{
    public:
    int ans1(vector<int>& nums, int k){
        int len = nums.size();
        sort(nums.begin(), nums.end());
        int ret = nums[len-k];
        
        return ret;
    }

    int ans2(vector<int>& nums, int k){
        int len = nums.size();
        priority_queue<int, vector<int>, less<int>> maxHeap;

        for(int i = 0; i != len; i++){
            maxHeap.push(nums[i]);
        }
        for(int i = 0; i != k-1; i++){
            maxHeap.pop();
        }
        return maxHeap.top();
    }
};

void test1(){
    Solution s;
    vector<int> nums = {3,2,1,5,6,4};
    int k = 2;

    // int ret = s.ans1(nums, k);
    int ret = s.ans2(nums, k);
    cout << ret << endl;
}

void test2(){
    Solution s;
    vector<int> nums = {3,2,3,1,2,4,5,5,6};
    int k = 4;

    // int ret = s.ans1(nums, k);
    int ret = s.ans2(nums, k);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();

    return 0;
}